package com.shanzmoo.core.domain;

import com.shanzmoo.base.bean.ValidList;
import com.shanzmoo.core.cache.CurrentUserCache;
import com.shanzmoo.base.util.BillNoUtils;
import com.shanzmoo.db.produce.entity.FactoryOrderEntity;
import com.shanzmoo.db.produce.entity.dto.FactoryOrderDeatailSaveDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.*;
import java.io.Serializable;

/**
 * 生产订单保存对象
 * @author: Gzhao 2020/12/15
 */
@Data
@ApiModel("生产订单保存对象")
public class FactoryOrderSaveDto implements Serializable {

    private static final long serialVersionUID = 1758L;

    @NotBlank(message = "刷机订单号不允许为空")
    @ApiModelProperty(value = "刷机订单号", example = "A201214193070")
    private String orderNo;

    @NotEmpty(message = "刷机组明细不允许为空")
    @ApiModelProperty(value = "刷机组明细")
    ValidList<FactoryOrderGroup> groupList;


    @Data
    public static class FactoryOrderGroup{
        @NotNull(message = "所属刷机组不允许为空")
        @ApiModelProperty(value = "所属刷机组", example = "1")
        private Integer rootGroupId;

        @NotEmpty(message = "刷机商品明细不允许为空")
        @ApiModelProperty(value = "刷机商品明细")
        ValidList<FactoryOrderDeatailSaveDto> deatailList;

        public FactoryOrderEntity convert(String orderNo, Integer memberId) {
            return FactoryOrderEntity.builder()
                    .orderNo(orderNo)
                    .memberId(memberId)
                    .rootGroupId(rootGroupId)
                    .productionNo(BillNoUtils.generateProduceNo())
                    .createUser(CurrentUserCache.getUserId())
                    .outletId(CurrentUserCache.getOutletId())
                    .build();

        }
    }
}
